<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>天下第一帅</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script>
		window.onload = function () {
			let obtn = document.getElementById('btn');
			obtn.onclick =function () {
				let xhr = new XMLHttpRequest()
				//如果兼容IE^
				if(window.XMLHttpRequest){
					xhr = new XMLHttpRequest()
				}else{
					xhr = new ActiveXObject('Microsoft.XMLHttp');
					//兼容IE6
				}
				//第三个参数就是异步和同步,如果是true就是异步,不会影响用户体验
				xhr.open('POST','1.php',true);
				//发送
                xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
				xhr.send('a=6&b=12');
				//接受
				xhr.onreadystatechange = function () {
					debugger
					if(xhr.readyState==4){
						if(xhr.status >=200&&xhr.status<300 || xhr.status==304){
							alert(xhr.responseText)
						}else{
							alert('失败')
						}
					}
				}
			}
		}
    </script>
</head>
<body>
<button id="btn">提交</button>
</body>
</html>